#!/usr/bin/node

const log = console.log;
const koa = require('koa');

let app = new koa();

//中间件M-hello
app.use((ctx,next)=>{
  if(ctx.method === 'GET' && ctx.path ==='/api/tasks/' ){
    log('find');
    ctx.body='查询成功';
  }

  if(ctx.method === 'POST' && ctx.path === '/api/tasks/'){
    log('add');
    ctx.body='添加成功'; 
  }

  if(ctx.method === 'PUT' && /\/api\/tasks\/(\d)+$/.test(ctx.path)){
    log('put');
    ctx.body='put成功';
  }

  if(ctx.method === 'DELETE' && /\/api\/tasks\/(\d)+$/.test(ctx.path)){
    log('delete');
    ctx.body='delete成功'; 
  }


});
app.listen(8080);

log('hello world');

